import {esri} from "../arcgisUtils/ArcgisTool";

class DigitalManagement {
  init() {
    let config = {
      uniqueId: "公交站点",
      // url:"http://120.40.102.239:9651/arcgis/rest/services/%E6%95%B0%E5%AD%97%E5%9B%AD%E6%9E%97%E6%95%B0%E6%8D%AE%E5%B1%95%E7%A4%BA10_2/MapServer/6",
      url: "http://11.23.3.109:6080/arcgis/rest/services/%E6%95%B0%E5%AD%97%E5%9F%8E%E7%AE%A1%E6%A1%88%E4%BB%B6%E5%88%86%E5%B8%83/MapServer/0",
      renderer: this.getRenderer(),
    }
    this.featureLayer = arcgisTool.manageLayer.applyFeatureLayer(config);
    let view = arcgisTool.manageView.getView();
    this._timer = null;
    this._event = esri.watchUtils.when(view, "zoom", (scale, v, c, evt) => {
      clearTimeout(this._timer);
      this._timer = setTimeout(() => {
        let renderScale =  12 + scale * 3;
        this.featureLayer.renderer = this.getRenderer(renderScale,renderScale);
      }, 500);
    });
  }
  clear(){
    if(this.featureLayer){
      this.featureLayer.visible = false;
    }
    if( this._event){
      this._event.remove();
    }
  }
  getRenderer(width = 32, height = 32) {
    let config = {
      "道路交通": "http://localhost:8080/static/images/道路交通.png",
      "公用设施": "http://localhost:8080/static/images/公共设施.png",
      "'街面秩序'": "http://localhost:8080/static/images/point_orange.png",
      "扩展事件": "http://localhost:8080/static/images/扩展事件.png",
      "其他设施": "http://localhost:8080/static/images/其他设施.png",
      "施工管理": "http://localhost:8080/static/images/施工管理.png",
      "市容环境": "http://localhost:8080/static/images/市容环境.png",
      "突发事件": "http://localhost:8080/static/images/突发事件.png",
      "宣传广告": "http://localhost:8080/static/images/宣传广告.png",
      "园林绿化": "http://localhost:8080/static/images/园林绿化.png",
    }
    let result = [];
    for (let key in config) {
      let url = config[key];
      result.push({
        value: key, // Category number
        symbol: {
          type: "picture-marker",
          url: url,
          width: width + "px",
          height: height + "px"
        }
      })
    }
    return {
      type: "unique-value",
      field: "大类名",
      uniqueValueInfos: result
    }
  }
}

export const digitalManagement = new DigitalManagement();
